package slice

import (
	"fmt"
	"strconv"
)

var s1 []string
var s2 = []int{1, 2, 3}

//切片就是可变长度的数组 是内置数据对象
func LenSlice() {
	ints := make([]int, 3, 5)

	ints[1] = 123
	for _, i := range ints {
		fmt.Println(strconv.FormatInt(int64(i), 10))
	}
}

//切片截取,index从0开始的，没有切片的
func SplitSlice() {
	numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
	numbers = append(numbers, 123)
	fmt.Println("numbers = ", numbers)
	fmt.Println("numbers[1:4] = ", numbers[1:4])
	fmt.Println("numbers[1:] = ", numbers[1:])
	fmt.Println("numbers[:2] = ", numbers[:2])
	ints := append(numbers, 10, 11, 12, 34)
	fmt.Println("ints = ", ints)
	numbers1 := make([]int, len(numbers), (cap(numbers))*2)
	copy(numbers1, numbers)
	fmt.Println("numbers1 = ", numbers1)
}
